﻿using System.Collections.ObjectModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Media.Imaging;

using Game.Objects;
using Game.Toolkit.Internal;
using Game.Types;

namespace Game.Toolkit
{
    public static class StandardInfrastructure
    {
        public static Collection<ObjectType> Railroad
        {
            get 
            {
                Collection<ObjectType> list = new Collection<ObjectType>();
                BitmapImage image = InfrastructureResourceFile.Railroad;

                double width = image.PixelWidth;
                double height = image.PixelHeight;
                
                int index = 0;
                for(int x = 0; x < 10; x++)
                {
                    for(int y = 0; y < 10; y++)
                    {
                        int left = x * 100;
                        int top = y * 100;
                        Point topLeft = new Point(left, top);
                        
                        if (x > 9)
                        {
                            continue;
                        }
                        
                        if (y > 6)
                        {
                            continue;
                        }
                        
                        //CroppedBitmap crop = new CroppedBitmap(image, new Int32Rect(0,0,48,52));
                        CroppedBitmap crop = new CroppedBitmap(
                            image, new Int32Rect(left, top, 48, 48));
                        
                        DrawingVisual drawingVisual = new DrawingVisual();
                        DrawingContext context = drawingVisual.RenderOpen();
            
                        var t = new TranslateTransform(0, 0);
                        context.PushTransform(t);
                        context.DrawImage(crop, new Rect(0, 0, 48, 48));
                        context.Close();
                        
                        RenderTargetBitmap target = new RenderTargetBitmap(
                            48, 48, 96, 96, PixelFormats.Pbgra32);
                        target.Render(drawingVisual);
            
                        ObjectTypeBuilder builder = new ObjectTypeBuilder();
                        builder.Name = "Railroad{X=" +
                            topLeft.Y + ",Y=" + topLeft.X  + "}";
                        builder.Picture = target;
                        builder.TerrainBit = Game.Terrain.TerrainBitTypes.Railroad;
                        list.Add(builder.BuildObjectType());
                        index++;
                    }
                }
                
                return list;
            }
        }

    }
}
